package com.neborosoft.lib.threading;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * User: CM
 * Date: 13.01.13
 * Time: 14:16
 * To change this template use File | Settings | File Templates.
 */
public final class Threading {
    public static ThreadPoolExecutor newSingleThreadExecutor(BlockingQueue<Runnable> queue){
        return new ThreadPoolExecutor(1, 1,
                        0L, TimeUnit.MILLISECONDS,queue);
    }

    public static ThreadPoolExecutor newExecutorWithSingleThreadAndSingleTaskQueue(){
        return newSingleThreadExecutor(new ArrayBlockingQueue<Runnable>(1));
    }

    private static Executor sharedExecutor;
    public static Executor getSharedExecutor(){
        if(sharedExecutor == null) {
            sharedExecutor = Executors.newSingleThreadExecutor();
        }

        return sharedExecutor;
    }
}
